<?php
/*
require_once('../model/m_schedules.php');


*/

require_once('../model/m_q_shifts.php');

class q_shifts{

	public $data = array();
	public $usersData = array();
	public $currentUser= "";	
	public $currentUserName= "";	
	public $currentDay= "";	
	public $qShiftData = array();	
	public $qShiftWeekData = array();	
	
	
	public function actionView(){
		//include_once("../views/v_session.php"); 
		include_once("../views/v_header_principal_q_shifts_ajax.html");
		include_once("../views/v_q_shifts.html");
		include_once("../views/v_footer_principal.html");
	}	
	
	public function actionViewMyQShift($username){
		include_once("../views/v_session.php"); 
		
		// only collect data if a username is specified
		if ($username != 'yes'){
			$this->qShiftData = getQShiftsUser($username);
			$this->currentUser= $this->qShiftData[0][0];
			$this->currentUserName= $this->qShiftData[0][1];
			$this->qShiftWeekData = getQShiftsUserWeek($username);
			
			include_once("../views/_v_q_shifts_myqshift.html");
			
		} else {
			include_once("../views/v_header_principal_q_shifts_ajax.html");
			include_once("../views/v_q_shifts_myqshift.html");
			include_once("../views/v_footer_principal.html");
		}
	}		
	
	public function actionSwap($username){
		include_once("../views/v_session.php"); 
				
		$this->usersData = getUsers();
		include_once("../views/v_header_principal_q_shifts_ajax.html");
		include_once("../views/v_q_shifts_swap.html");
		include_once("../views/v_footer_principal.html");
	
	}	

		
	public function actionSwapGrid($requestor,$target){
				
		$this->data = getSwapData($requestor,$target);		
		include_once("../views/_v_q_shifts_swap.html");
	}	
		
	public function actionDoSwap($weekday,$requestor,$requestorShift,$target,$targetShift){
				
		$result = doSwap($weekday,$requestor,$requestorShift,$target,$targetShift);	
		
		if($result){
			echo "<br><br><span class='top-bar'><h1>SWAP Saved Successfully!!! &nbsp";
			echo "<image src='../images/check-icon.gif' width=20px height=20px></h1></span><br><br>";
			exit;
		} else 
			echo "<h1> Error saving SWAP. Ping michamen@cisco.com</h1>";

	}	
	
	public function actionViewDay($day){
		if($day=='Today'){		
			$date = new DateTime("now");
			$date->setTimeZone(new DateTimeZone("America/Costa_Rica"));
			$day= $date->format('l');
		}	
		$this->currentDay = $day;
		$this->qShiftData = getQShifts($day); //Get shifts for today
		include_once("../views/_v_q_shifts_day.html");
	}

}

$instancia= new q_shifts;

if(isset($_GET['view'])){
	if($_GET['view']=="list")	
		$instancia->actionView();
}

if(isset($_GET['viewDay'])){
	$instancia->actionViewDay($_GET['viewDay']);
}

if(isset($_GET['viewMyQShift'])){
	$instancia->actionViewMyQShift($_GET['viewMyQShift']);
}

if(isset($_GET['swap'])){
	$instancia->actionSwap($_GET['swap']);
}

if(isset($_GET['swapRequestor'])){
	$instancia->actionSwapGrid($_GET['swapRequestor'],$_GET['target']);
}

if(isset($_GET['doSwap'])){
	$instancia->actionDoSwap($_GET['DoW'],$_GET['userA'],$_GET['qshiftA'],$_GET['userB'],$_GET['qshiftB']);
}


?>